package com.ams.admin.utils.wx;

import lombok.Data;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @Author: Like
 * @Date: 2023/5/26 14:08
 * @Description:
 */
@Data
@Slf4j
@Component
public class WxParameter {
    @Value("${wx.appId}")
    private String MP_APP_ID;
    @Value("${wx.appSecret}")
    private String MP_APP_SECRET;
    @Value("${wx.code2Session}")
    private String OPENID_URL;

    public String getOpenidUrl(String code){
        String url = "{OPENID_URL}?appid={MP_APP_ID}&secret={MP_APP_SECRET}&js_code={code}&grant_type=authorization_code";
        String newUrl = url.replace("{OPENID_URL}",OPENID_URL)
                .replace("{MP_APP_ID}",MP_APP_ID)
                .replace("{MP_APP_SECRET}",MP_APP_SECRET)
                .replace("{code}",code);
        return newUrl;
    }
}
